package com.realtyManage.springboot.Service.impl;

import com.realtyManage.springboot.Dao.*;
import com.realtyManage.springboot.Model.Do.*;
import com.realtyManage.springboot.Model.Vo.BaseEntity;
import com.realtyManage.springboot.Model.Vo.DictionariesEntity;
import com.realtyManage.springboot.Service.AreaService;
import com.realtyManage.springboot.Service.DictionariesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.Predicate;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class DictionariesServiceImpl implements DictionariesService {
    @Autowired
    private DictionariesRepository dictionariesRepository;

    @Autowired
    private DictionariesOneRepository dictionariesOneRepository;

    @Autowired
    private DictionariesTwoRepository dictionariesTwoRepository;

    @Autowired
    private DictionariesZeroRepository dictionariesZeroRepository;

    @Override
    public List<Dictionaries> findDictionaries() {
        return dictionariesRepository.findDictionaries();
    }

    @Override
    public List<DictionariesZero> findDictionariesZero() {
        return dictionariesZeroRepository.findDictionariesZero();
    }

    public List<DictionariesOne> findDictionariesOne() {
        return dictionariesOneRepository.findDictionaries();
    }

    public List<DictionariesTwo> findDictionariesTwo() {
        return dictionariesTwoRepository.findDictionaries();
    }


    @Override
    public List<Dictionaries> findDictionariesType(String type) {
        return dictionariesRepository.findDictionariesType(type);
    }

    @Override
    public Dictionaries findById(Integer id) {
        return dictionariesRepository.findById(id).orElse(null);
    }


    public DictionariesOne findByIdOne(Integer id) {
        return dictionariesOneRepository.findById(id).orElse(null);
    }

    public DictionariesTwo findByIdTwo(Integer id) {
        return dictionariesTwoRepository.findById(id).orElse(null);
    }

    @Override
    public Dictionaries save(Dictionaries dictionaries) {
        return dictionariesRepository.saveAndFlush(dictionaries);
    }

    public DictionariesOne saveOne(DictionariesOne dictionariesOne) {
        return dictionariesOneRepository.saveAndFlush(dictionariesOne);
    }

    public DictionariesTwo saveTwo(DictionariesTwo dictionariesTwo) {
        return dictionariesTwoRepository.saveAndFlush(dictionariesTwo);
    }

    @Override
    public int deleteDictionaries(Integer menuId,String parentId) {
        //删除父节点在内
        if (parentId.equals("0")){
            return dictionariesRepository.setIsShows(menuId);
        }else{
            return dictionariesRepository.setIsShow(menuId);
        }
    }

    public int deleteDictionariesOne(Integer menuId,String parentId) {
        //删除父节点在内
        if (parentId.equals("0")){
            return dictionariesOneRepository.setIsShows(menuId);
        }else{
            return dictionariesOneRepository.setIsShow(menuId);
        }

    }

    public int deleteDictionariesTwo(Integer menuId,String parentId) {
        //删除父节点在内
        if (parentId.equals("0")){
            return dictionariesTwoRepository.setIsShows(menuId);
        }else{
            return dictionariesTwoRepository.setIsShow(menuId);
        }

    }

    @Override
    public List<Dictionaries> findLevelUser(Integer level) {
        return dictionariesRepository.findLevelUser(level);
    }

}
